﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using tophd2.Classes;
using tophd2.Classes.Helper;

namespace tophd2
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }
        
        protected void Application_Start()
        {
            ViewEngines.Engines.Clear();
            //Add WebForm Engine
            ViewEngines.Engines.Add(new WebFormViewEngine());
            ModelMetadataProviders.Current = new DataAnnotationsModelMetadataProvider();
            AreaRegistration.RegisterAllAreas();
            AppRouteMap.RegisterRoutes(RouteTable.Routes);
            try
            {
                System.Reflection.PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
                object o = p.GetValue(null, null);
                System.Reflection.FieldInfo f = o.GetType().GetField("_dirMonSubdirs", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.IgnoreCase);
                object monitor = f.GetValue(o);
                System.Reflection.MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                m.Invoke(monitor, new object[] { });

                //Add Cybersource payment gateway information into application variable
                //Application.Add("PaymentGateways", StoreFrontCurrencyConversion.GetAllPaymentGateway());
                //Application.Add("SupportedLanguages", LanguageEntityService.GetAllLanguages());
                //Application.Add("AllCountries", CountryEntityService.GetAllCountry());
                //Application.Add("SymbianDevice", DeviceEntityService.GetSymbianDevices());
                //Application.Add("Features", FeatureService.GetAllFeatures());
            }
            catch
            {
            }


            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new MobileCapableWebFormViewEngine());
        }
    }
}